package org.misalen.web.server.controllers.user;

import java.util.UUID;

import org.misalen.annotations.ControllerApi;
import org.misalen.annotations.InterfaceApi;
import org.misalen.web.server.config.ServerResult;
import org.misalen.web.server.config.ServerUrl;
import org.misalen.web.server.controllers.BaseController;
import org.misalen.web.server.result.user.UploadImageResult;
import org.misalen.web.service.file.InfoType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@ControllerApi(value = "上传", description = "上传图片", index = 200)
@RequestMapping(value = ServerUrl.UserUploadControllerUrl)
public class UserUploadController extends BaseController {

	@RequestMapping(value = "/image", method = { RequestMethod.POST })
	@InterfaceApi(value = "上传图片", resultClass = UploadImageResult.class)
	public @ResponseBody ServerResult image(MultipartFile file) throws Exception {
		String url = ossFile.uploadFile(file.getInputStream(),
				UUID.randomUUID() + getExtensionName(file.getOriginalFilename()), InfoType.imageCode);
		UploadImageResult imageResult = new UploadImageResult();
		imageResult.setImgUrl(url);
		return ServerResult.ok(imageResult);
	}

}
